package hrm.action.insa.familyaction;

import hrm.action.Action;
import hrm.action.ActionForward;
import hrm.dto.insa.EmployeeDTO;
import hrm.dto.insa.FamilyDTO;
import hrm.dto.login.LoginDTO;
import hrm.serviceimple.EmployeeServiceImple;
import hrm.serviceimple.FamilyServiceImple;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class InsaListFamilyAction implements Action{
	public ActionForward execute(HttpServletRequest request,
			HttpServletResponse response) {
		// TODO Auto-generated method stub	
		
		ActionForward actfoward = new ActionForward();
		EmployeeServiceImple service = EmployeeServiceImple.getInstance();
		FamilyServiceImple familyservice = FamilyServiceImple.getInstance();
		
		EmployeeDTO dto = new EmployeeDTO();
		dto.setId(getFindId(request));
		dto = service.getEmployee(dto);		
		
		FamilyDTO fdto =  new FamilyDTO();
		fdto.setId(getFindId(request));
		List<FamilyDTO> dtolist = familyservice.getFamily(fdto);
		
		request.setAttribute("employeeDTO", dto);
		request.setAttribute("FamilyList", dtolist);
		actfoward.setUrl("familyList");
		return actfoward;
	}
	
	private String getFindId(HttpServletRequest request){
		
		String findid = (String) request.getSession().getAttribute("findid");
		if(findid == null){
			findid = ((LoginDTO)request.getSession().getAttribute("login")).getId();
			request.setAttribute("findid", findid);
		}
		return findid; 
	}
}